(function() {
  var express, iced, pgsql, router, __iced_k, __iced_k_noop;

  iced = require('iced-runtime');
  __iced_k = __iced_k_noop = function() {};

  express = require('express');

  pgsql = require('pg');

  router = express.Router();

  module.exports = router;

  router.all('/', function(req, res, next) {
    var client, done, err, fmt_pan, record, result, settl_date, where_clause, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    where_clause = "(\n    serial::text like $1 or acqu_id like $1 or fowd_id like $1 or\n    trace_num like $1 or pri_acct like $1 or trans_amt like $1 or\n    term_id like $1 or acpt_id like $1 or retref_num like $1 or\n    fowd_settl like $1 or acqu_settl like $1 or order_id like $1\n)";
    settl_date = req.body.settl_date || req.query.settl_date || moment().subtract(1, 'd').format('YYYY-MM-DD');
    where_clause += "and year = " + (settl_date.substring(0, 4)) + "\nand settl_date = '" + (settl_date.substring(5, 7) + settl_date.substring(8, 10)) + "'";
    res.locals.settl_date = settl_date;
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/upay/acoma.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 27
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/upay/acoma.coffee"
          });
          client.query("select count(*) as count from upay_acoma where " + where_clause, ['%' + res.locals.keyword + '%'], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 34
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          res.locals.total = result.rows[0].count;
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/upay/acoma.coffee"
            });
            client.query("select * from upay_acoma where " + where_clause + " order by serial desc offset $2::int limit $3::int", ['%' + res.locals.keyword + '%', res.locals.offset, res.locals.page_rows], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 45
            }));
            __iced_deferrals._fulfill();
          })(function() {
            var _i, _len, _ref;
            if (err) {
              done(client);
              return next(err);
            }
            done();
            fmt_pan = function(pri_acct) {
              var len;
              if (!pri_acct || pri_acct.length < 9) {
                return pri_acct;
              }
              len = pri_acct.length;
              return pri_acct = pri_acct.substring(0, 4) + ' .. ' + pri_acct.substring(len - 4, len);
            };
            _ref = result.rows;
            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
              record = _ref[_i];
              record.pri_acct = fmt_pan(record.pri_acct);
            }
            return res.render('upay/acoma/index', {
              records: result.rows
            });
          });
        });
      };
    })(this));
  });

}).call(this);
